//
// Created by 田建昆 on 2020/12/21.
//

#include <sort.h>
#include <stdio.h>
#include <string.h>

static void sort(char *name, int arr[], int size) {
    if (strcmp(name, "selection") == 0) {
        printf("selection sort result:");
        selection(arr, size);
    } else if (strcmp(name, "insertion") == 0) {
        printf("insertion sort result:");
        insertion(arr, size);
    } else if (strcmp(name, "shell") == 0) {
        printf("shell sort result:");
        shell(arr, size);
    } else if (strcmp(name, "bu_merge") == 0) {
        printf("bu_merge sort result:");
        bu_merge(arr, size);
    } else if (strcmp(name, "td_merge") == 0) {
        printf("td_merge sort result:");
        td_merge(arr, size);
    }  else if (strcmp(name, "quick") == 0) {
        printf("quick sort result:");
        quick(arr, size);
    }else if (strcmp(name, "heap") == 0) {
        printf("quick sort result:");
        heap(arr, size);
    } else {
        printf("not found!");
        exit(1);
    }
}

int main(int argc, char **argv) {

    int a[] = {100, 60, 200, 150, 1000, 600, 400, 230, 20, 130, 100000, 20000, 122};
    int n = sizeof(a) / sizeof(a[0]);
    if (argc >= 2) {
        sort(argv[1], a, n);
    } else {
        heap(a, n);
    }
    for (int i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}